package com.dks.controller.student;


import com.dks.dto.student.StudentTaskAddDto;
import com.dks.repository.IStudentClassRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import com.dks.util.PageInfo;
import com.dks.vo.student.StudentTaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 学生作业相关
 */
@RestController
@RequestMapping("student-task")
public class StudentTaskController {

    @Autowired
    private IStudentClassRepository studentClassRepository;


    /**
     * 作业提交
     *
     * @author evan
     */
    @PostMapping("add")
    public ResultModel<Boolean> add(@RequestBody StudentTaskAddDto studentTaskAddDto) {
        return studentClassRepository.addTask(studentTaskAddDto);
    }

    /**
     * 作业查询-列表
     * 查询条件：userId 请求人id 班级id(qsClassId)、学生id(studentId)
     *
     * @author evan
     */
    @GetMapping("list")
    public ResultModel<PageInfo<StudentTaskVo>> list(@RequestParam(value = "userId", required = false) Long userId,
                                                     @RequestParam(value = "parentId", required = false) Long parentId,
                                                     @RequestParam(value = "qsClassId", required = false) Long qsClassId,
                                                     @RequestParam(value = "studentId", required = false) Long studentId,
                                                     @RequestParam(value = "status", required = false) Integer status,
                                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                     @RequestParam(value = "pageSize", defaultValue = "15") Integer pageSize) {
//        if (userId == null){
//            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "userId");
//        }
        return studentClassRepository.listTask(userId, parentId, qsClassId, studentId, status, pageNum, pageSize);
    }

    /***
     * 作业查询-详情
     * @author evan
     */
    @GetMapping("detail")
    public ResultModel<StudentTaskVo> detail(@RequestParam("userId") Long userId, @RequestParam("taskId") Long taskId) {
        if (taskId == null) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "taskId");
        }
        if (userId == null) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "userId");
        }
        return studentClassRepository.taskDetail(userId, taskId);
    }

    /***
     * 作业查询-详情
     * @author evan
     */
    @GetMapping("requirement/{classId}")
    public ResultModel<Object> detail(@PathVariable(value = "classId") Long classId) {
        if (classId == null) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "classId");
        }
        return studentClassRepository.getTaskRequirement(classId);
    }


}
